package com.bjgzy.rating.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bjgzy.rating.R;
import com.bjgzy.rating.mvp.contract.EntriesContract;
import com.bjgzy.rating.mvp.model.EntriesModel;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.EntriesData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.FragmentScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-7 17:12:55
 */
@Module
public abstract class EntriesModule {

    @Binds
    abstract EntriesContract.Model bindEntriesModel(EntriesModel model);

    @FragmentScope
    @Provides
    static List<EntriesData> provideList() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    static BaseQuickAdapter<EntriesData, AutoBaseViewHolder> provideActivityAdapter(List<EntriesData> list) {
        return new BaseQuickAdapter<EntriesData, AutoBaseViewHolder>(R.layout.rating_rv_item_entries, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, EntriesData item) {
                Glide.with(helper.itemView.getContext())
                        .load(item.getImg())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_logo));
                helper.setText(R.id.tv_title, item.getWorksName());
                helper.setText(R.id.tv_vote, item.getVoteCount() + " 票");
                helper.setText(R.id.tv_no, item.getResearchWorksNo());
                helper.setText(R.id.tv_name, item.getUnionName());
                helper.addOnClickListener(R.id.btn_vote);
                helper.setVisible(R.id.btn_vote, item.getUserRight().getCouldVote() == 1);
            }

        };
    }

    @FragmentScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(EntriesContract.View view) {
        return new GridLayoutManager(view.getActivity(), 2);
    }

}